package cn.panda.edu.controller;

import cn.panda.edu.model.Video;
import cn.panda.edu.service.VideoService;
import cn.panda.edu.util.FileUtil;
import cn.panda.edu.util.ResultDataUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**  
 * 类描述：  
 * @author: 苑庆涛 
 * @date： 2018-01-18 上午10:39:35  
 */
@RestController
@RequestMapping("/api/teacher/video")
public class TeacherVideoController {
	
	@Autowired
	private VideoService videoService;
	
	
	@ApiOperation(value = "添加视频")
	@RequestMapping(value = "insert", method = RequestMethod.POST)
	public Object insert(Video video,
            HttpServletRequest request) {
		int status=200;
		String message=null;
		try {
			videoService.insertSelective(video);
			status=200;
			message="添加成功!";
		} catch (Exception e) {
			status=500;
			message="添加失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}
	@ApiOperation(value = "上传视频")
	@RequestMapping(value = "upload", method = RequestMethod.POST)
	public  Object update(@RequestParam("file") MultipartFile file,
            HttpServletRequest request) {
		int  status=200;
		String message=null;
        String filePath = null;
        try {
            filePath = FileUtil.uploadFile(file) ;
        } catch (Exception e) {
        	e.printStackTrace();
        }
		return ResultDataUtil.resData(status, message,filePath);
	}
}
